package p41_autoconfig;

import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.SimpleCommandLinePropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.type.AnnotationMetadata;

@Configuration
@Import(_4_mvc自动配置.MyDeferredImportSelector.class)
public class _4_mvc自动配置 {
    public static void main(String[] args) {
        AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
        context.registerBean(_4_mvc自动配置.class);
        context.refresh();

        for (String name : context.getBeanDefinitionNames()) {
            if (context.getBeanDefinition(name).getResourceDescription() != null) {
                System.out.println("===>" + name + " -> " + context.getBeanDefinition(name).getResourceDescription());
            }
        }
    }

    static class MyDeferredImportSelector implements DeferredImportSelector {
        @Override
        public String[] selectImports(AnnotationMetadata importingClassMetadata) {
            return new String[]{
                    //内嵌tomcat服务器工厂自动配置类
                    ServletWebServerFactoryAutoConfiguration.class.getName(),
                    //DispatcherServlet自动配置类
                    DispatcherServletAutoConfiguration.class.getName(),
                    //DispatcherServlet运行时的所有组件(处理器映射器、适配器等...)自动配置类
                    WebMvcAutoConfiguration.class.getName(),
                    //BasicErrorController自动配置类
                    ErrorMvcAutoConfiguration.class.getName()
            };
        }
    }
}
